
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


/****** Object:  Trigger dbo.l_vip_afterinsert    Script Date: 2013-8-26 10:51:46 ******/
CREATE  trigger [dbo].[td_posmember_ai]
on [dbo].[td_posmember] after  insert
-- instead of delete
as
begin
  set nocount on
  declare @vipid int,@oldcardid int
	
  DECLARE old_cursor CURSOR FORWARD_ONLY OPTIMISTIC FOR SELECT id,oldcardid FROM inserted
  OPEN old_cursor
  FETCH NEXT FROM old_cursor INTO @vipid,@oldcardid
  WHILE(@@FETCH_STATUS=0)
  BEGIN
	if (@oldcardid is not null)
	  update td_posmember set newcardid = @vipid 
		where id = @oldcardid
	FETCH NEXT FROM old_cursor INTO @vipid,@oldcardid
  END
  CLOSE old_cursor
  DEALLOCATE old_cursor	

end



GO


